package com.controller;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.PointGoods;
import com.entity.ZhiyuanzheEntity;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import com.service.PointGoodsService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;


@Api(tags = "积分商品信息")
@RestController
@RequestMapping("/pointGoods")
public class PointGoodsController {
    @Autowired
    private PointGoodsService pointGoodsService;

    @ApiOperation(value = "查询所有商品信息")
    @RequestMapping("/findAll")
    public R findAllPointGoods(@RequestParam Map<String, Object> params, PointGoods pointGoods,
                               HttpServletRequest request) {
        EntityWrapper<PointGoods> ew = new EntityWrapper<PointGoods>();


        PageUtils page = pointGoodsService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, pointGoods), params), params));
        return R.ok().put("data", page);
    }
    @ApiOperation(value = "新增商品")
    @RequestMapping("/insert")
    public R insert(@RequestBody PointGoods pointGoods) {
        return R.ok().put("data",pointGoodsService.insert(pointGoods));
    }
    @ApiOperation(value = "修改商品")
    @RequestMapping("/update")
    public R update(@RequestBody PointGoods pointGoods) {

        return R.ok().put("data",pointGoodsService.updateById(pointGoods));
    }
    @ApiOperation(value = "删除商品")
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        pointGoodsService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        return R.ok().put("data", pointGoodsService.selectById(id));
    }

    /**
     * 前端详情
     */

    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Integer id){
        return R.ok().put("data", pointGoodsService.selectById(id));
    }
}
